home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / dev / scsiDevice.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  8.2 KB  |  191 lines

  1. /*
  2.  * scsiDevice.h --
  3.  *
  4.  *    Declarations of Sprite interface to SCSI devices.  
  5.  *    This file defines the interface to SCSI devices which consists 
  6.  *    of three operations: Attach the device, Release the device, and
  7.  *    send a SCSI command block to the device. 
  8.  *
  9.  *    INTERFACE SUMMARY: 
  10.  *
  11.  *    To interface to a SCSI device, the SCSI command formatter must first
  12.  *    attach the device.  This is done by calling DevScsiAttachDevice() with
  13.  *    the Fs_Device structure for the device. DevScsiAttachDevice 
  14.  *    returns a ScsiDeviceHandle that contains the queue to insert 
  15.  *    scsi command blocks for the device. The handle also 
  16.  *    contains the procedure to call to release the device.
  17.  *       
  18.  *
  19.  * Copyright 1989 Regents of the University of California
  20.  * Permission to use, copy, modify, and distribute this
  21.  * software and its documentation for any purpose and without
  22.  * fee is hereby granted, provided that the above copyright
  23.  * notice appear in all copies.  The University of California
  24.  * makes no representations about the suitability of this
  25.  * software for any purpose.  It is provided "as is" without
  26.  * express or implied warranty.
  27.  *
  28.  * $Header: /cdrom/src/kernel/Cvsroot/kernel/dev/scsiDevice.h,v 9.2 91/08/19 13:45:58 jhh Exp $ SPRITE (Berkeley)
  29.  */
  30.  
  31. #ifndef _SCSIDEVICE
  32. #define _SCSIDEVICE
  33.  
  34. #include <list.h>
  35. #include <devQueue.h>
  36. #include <user/fs.h>
  37. #include <fs.h>
  38. #include <sys/scsi.h>
  39.  
  40. /*
  41.  * The ScsiCmd data structure contains the information that a SCSI device 
  42.  * to execute a SCSI command. It is the object enqueue on a SCSI device's 
  43.  * request queue. Note that the bytes of the SCSI command block over 16 
  44.  * bytes directly follow this data structure.
  45.  */
  46. struct ScsiCmd {
  47.     List_Links    queuePtr;    /* List for queueing in HBA. Because we
  48.                  * use the DevQueue routines this element
  49.                  * MUST be the first in the structure.     */
  50.     Boolean    dataToDevice;    /* TRUE -> data is transferred to the device.
  51.                  * FALSE -> data is transferred from the device.
  52.                  * Meaningless if bufferLen is 0. */
  53.     int        bufferLen;    /* The length of the data buffer in bytes. */
  54.     Address    buffer;        /* The data buffer for this command. */
  55.                 /* Routine to called when command completes. */
  56.     int        (*doneProc) _ARGS_((struct ScsiCmd *scsiCmdPtr, 
  57.                 ReturnStatus status, int statusByte, 
  58.                 int byteCount, int senseLength, 
  59.                 Address senseDataPtr));
  60.     ClientData clientData;    /* A word of data available to the caller. 
  61.                  * This item is not changed by the Device. */
  62.     int           commandBlockLen;    /* Length of the SCSI command block. The
  63.                  * data of the SCSI command block immediately
  64.                  * follows this data structure and continues
  65.                  * for commandBlockLen bytes. */
  66.     char    commandBlock[16]; /* The first 16 bytes of the SCSI command
  67.                    * block.  The rest of the command directly
  68.                    * follows the first 16 bytes. */
  69.     int        senseLen;    /* Length of sense data. */
  70.     char    senseBuffer[SCSI_MAX_SENSE_LEN]; /* Sense buffer. */
  71.     int        statusByte;    /* Sense byte from scsi command. */
  72. };
  73. typedef struct ScsiCmd ScsiCmd;
  74.  
  75. /*
  76.  * A device attached to a SCSI Bus is described by the following stucture. 
  77.  * A pointer to a ScsiDevice is returned by the DevScsiAttachDevice
  78.  * routine and contains the device queue to use to 
  79.  * send commands to the device. The fields of the structure are 
  80.  * initialize by the attached routine and should not be modified or copied
  81.  * by the SCSI formatting routines. The pointer passed to the 
  82.  * and releaseProc procedures should be the same value returned by the
  83.  * attachProc. 
  84.  */
  85.  
  86. typedef struct ScsiDevice {
  87.     DevQueue      devQueue;         /* Queue to send request for this 
  88.                       * device. Once the request has been
  89.                       * processed, the caller 
  90.                       * caller by calling function sepcified
  91.                       * in the SCSICmd structure.  */
  92.     char     *locationName;         /* A string used to identify the device's
  93.                       * location in error messages produced
  94.                       * the SCSI formatting routines. An 
  95.                       * Example would be:
  96.                       * "HBA 2 Bus 1 Target 6 LUN 2". */
  97.     int        LUN;              /* SCSI Logical unit number of device.
  98.                        * This is stored here because the
  99.                        * SCSI command formatter needs to 
  100.                        * know the LUN to build command
  101.                        * blocks. */
  102.                      /* Routine to release the system 
  103.                       * resources used by the device. */
  104.     ReturnStatus (*releaseProc) _ARGS_((struct ScsiDevice *scsiDevicePtr));   
  105.     int     maxTransferSize;         /* Maximum size of data transfer to 
  106.                       * this device supported by the HBA. */
  107.     int         inquiryLength;         /* Length in bytes of the inquiryData 
  108.                       * pointed to by inquiryDataPtr. */
  109.     char     *inquiryDataPtr;    /* Data return by the INQUIRY command 
  110.                       * sent to the device. */
  111.     int        referenceCount;         /* Count of number of references to this
  112.                       * device handle. */
  113.                      /* Routine to call if the statusByte
  114.                       * returned by a command is non-zero. */
  115.     ReturnStatus (*errorProc) _ARGS_((struct ScsiDevice *devPtr, 
  116.                     ScsiCmd *scsiCmdPtr));     
  117.     ClientData    clientData;         /* Whatever you want it to be. */
  118.  
  119. } ScsiDevice;
  120.  
  121.  
  122. /*
  123.  * Upon command completion the routine specified by doneProc in the
  124.  * ScsiCmd data structure is called with the following arguments:
  125.  *    (*doneProc)(scsiCmdPtr, errorCode, scsiStatusByte, 
  126.  *            amountTransferred, senseDataLen, senseDataPtr);
  127.  *    where
  128.  * ScsiCmd   *scsiCmdPtr  - The scsiCmdPtr argument passed to sendCmdProc.
  129.  * ReturnStatus errorCode  - The error code from the HBA.
  130.  * unsigned char scsiStatusByte - The scsi status byte as returned by the SCSI 
  131.  *                      command.
  132.  * int     amountTransferred - Number of bytes of data transferred by this 
  133.  *                 command.
  134.  * int   senseDataLen -   The length in bytes of the SCSI sense info returned.
  135.  *              This number will be zero useless the scsiStatusByte
  136.  *              has the SCSI check condition bit set.
  137.  * char *senseDataPtr -   Pointer to scsi sense blocks.  This block will no
  138.  *              longer be valid once the call back routine returns.
  139.  *              (i.e. You must copy it if you want to save it.)
  140.  * 
  141.  * scsiDoneProc may be called at interrupt level so it should use
  142.  * appropriate locking and be relatively simple. Also, scsiDoneProc
  143.  * maybe called before the sendCmdProc proc returns.
  144.  */
  145.  
  146.  
  147. /*
  148.  * DevScsiSendCmd is normally encoded as macros for speed and reduced
  149.  * calling depth.
  150.  * If lint is being run we use the real routines in devScsiDevice.c to 
  151.  * permit type checking. Documentation on the calling sequence is found
  152.  * in devScsiDevice.c.
  153.  */
  154. #ifndef lint
  155. #define    DevScsiSendCmd(handlePtr, scsiCmdPtr) \
  156.     (Dev_QueueInsert((handlePtr)->devQueue,(List_Links *) (scsiCmdPtr)))
  157. #else
  158. extern void          DevScsiSendCmd();
  159. #endif
  160.  
  161. #define    MAX_SCSI_ERROR_STRING    128
  162. extern int devScsiNumErrors[];
  163. extern char **devScsiErrors[];
  164.  
  165. extern ScsiDevice *DevScsiAttachDevice _ARGS_((Fs_Device *devicePtr,
  166.     void (*insertProc)()));
  167. extern ReturnStatus DevScsiSendCmdSync _ARGS_((ScsiDevice *scsiDevicePtr,
  168.     ScsiCmd *scsiCmdPtr, int *amountTransferredPtr));
  169. extern ReturnStatus DevScsiReleaseDevice _ARGS_((ScsiDevice *scsiDevicePtr));
  170. extern ReturnStatus DevScsiTestReady _ARGS_((ScsiDevice *scsiDevicePtr));
  171. extern ReturnStatus DevScsiReadBlockLimits _ARGS_((ScsiDevice *scsiDevicePtr,
  172.     int *minPtr, int *maxPtr));
  173. extern ReturnStatus DevScsiStartStopUnit _ARGS_((ScsiDevice *scsiDevicePtr,
  174.     Boolean start));
  175. extern ReturnStatus DevScsiModeSense _ARGS_((ScsiDevice *scsiDevicePtr,
  176.     int disableBlockDesc, int pageControl, int pageCode, int vendor, 
  177.     int *sizePtr, char *bufferPtr));
  178. extern ReturnStatus DevScsiRequestSense _ARGS_((ScsiDevice *scsiDevicePtr,
  179.     int clearCount, int vendor, int *sizePtr, char *bufferPtr));
  180. extern ReturnStatus DevScsiReadPosition _ARGS_((ScsiDevice *scsiDevicePtr,
  181.     int blockType, ScsiReadPositionResult *positionPtr));
  182. extern ReturnStatus DevScsiIOControl _ARGS_((ScsiDevice *devPtr,
  183.     Fs_IOCParam *ioctlPtr, Fs_IOReply *replyPtr));
  184. extern ScsiDevice *DevNoHBAAttachDevice _ARGS_((Fs_Device *devicePtr,
  185.     void (*insertProc)()));
  186. extern Boolean DevScsiMapClass7Sense _ARGS_((int senseLength, char *senseDataPtr, ReturnStatus *statusPtr, char *errorString));
  187. extern ReturnStatus DevScsiGroup0Cmd _ARGS_((ScsiDevice *devPtr, int cmd, unsigned int blockNumber, unsigned int countNumber, register ScsiCmd *scsiCmdPtr));
  188.  
  189. #endif /* _SCSIDEVICE */
  190.  
  191.